require('../../lib/captcha/regjigsawmin.js');
require('../../assets/css/index.js');//引入的是公共css和复用css
const dom = require('../../utils/dom.js');  //引入节点操作js
require('./register.less');//自己
let https = require('../../utils/https.js')
//验证有没有被注册
dom.getE('#Tel').addEventListener('blur', () => {
    https.post('/api/user/isExist', {
        account: dom.getE('#Tel').value,
    }, res =>
        res.errno === 10002 ? alert(dom.getE('#Tel').value + '用户名已注册，请更换') : alert(dom.getE('#Tel').value + '可以注册'))
})

//用户需要点击后才能显示提交按钮
dom.getE('#Checkbox').addEventListener('click', function () {
    if (dom.getE('#Checkbox input').checked) {
        dom.getE('.btn').classList.remove('off')
        dom.getE('.Imagverification').classList.remove('off')
    } else {
        dom.getE('.btn').classList.add('off')
    }
})

//用户检测后提交
dom.getE('.btn').addEventListener('click',() => {
    if (dom.getE('#PassWord').value === dom.getE('#Confirm').value) {
        https.post('/api/user/register', {
            account: dom.getE('#Tel').value,
            password: dom.getE('#PassWord').value
        },  res=> {
            if (res.errno === 10002) {
                alert(res.message)
            } else if (res.errno === 0) {
                alert('恭喜你注册成功，你的登录名名为=>' + res.data.nickName
                )
            }
        })
    }else{
        alert('请确认密码输入一致') 
    }
})
//用户图片验证码
jigsaw.init({
    el: dom.getE('#captcha'),
    onSuccess: function() {
      alert('验证通过')
      dom.getE('.Imagverification').classList.add('off')
    }
  })
  //显示密码
  let yanjing1
  dom.getE('.icon-mimaxianshi').addEventListener('click',()=>{
       if(yanjing1){
        dom.getE('#Confirm').type='text'
        dom.getE('#PassWord').type='text'
        yanjing1=false
       }else{
        dom.getE('#PassWord').type='password'
        dom.getE('#Confirm').type='password'
        yanjing1=true
       }
  })
  